new Vue({
    el: '#app',
    data() {
        return {
            loading: false,
            tableData: [],
            form: {//查询筛选
                isCommentNull: '0',
                keepState: '0',
                Data: '',
                Page: 1, //页码
                Limit: 20
            },
            Total: 0,
        }
    },
    mounted() {
        const tableForm = localStorage.getItem("tableForm");
        if (tableForm) {
            this.form = JSON.parse(tableForm);
        }
        this.getList(this.form);
    },
    methods: {
        handleSerach() { //筛选
            this.form.Page = 1;
            if (this.form.keepState == '1') {
                localStorage.setItem('tableForm', JSON.stringify(this.form));
            } else {
                localStorage.removeItem('tableForm')
            }
            this.getList(this.form)
        },
        handleSizeChange(newSize) {
            this.form.Page = 1;
            this.form.Limit = newSize;
            if (this.form.keepState == '1') {
                localStorage.setItem('tableForm', JSON.stringify(this.form));
            } else {
                localStorage.removeItem('tableForm')
            }
            this.getList(this.form);
        },
        handleCurrentChange(newPage) {
            this.form.Page = newPage;
            if (this.form.keepState == '1') {
                localStorage.setItem('tableForm', JSON.stringify(this.form));
            } else {
                localStorage.removeItem('tableForm')
            }
            this.getList(this.form);
        },
        getList(data) {
            this.loading = true;
            httpRequest({
                hostApi: BASE_URL1,
                url: '/generalPaginationQueryTableNameDetail',
                data,
                type: "GET",
            }).then(res => {
                console.log(res);
                if (res.Status == 'success') {
                    this.Total = res.Total;
                    this.tableData = res.Data;
                } else {
                    this.$message({
                        message: '查询失败，请联系开发者!',
                        type: 'error'
                    })
                }
            }).catch(xhr => {
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }).finally(() => {
                this.loading = false;
            })
        },
        handleCommand(val, row) {//下单选项卡
            this[val](row);
        },
        handleAdd() {
            sessionStorage.setItem("Url", "");
            window.location.href = './sql_config.html?action=Add'
        },
        handleEdit(row) {
            window.location.href = "./edit.html?nodeKey=" + row.TABLE_NAME;
        },
        handleShow(row) {
            window.location.href = './show.html?nodeKey=' + row.TABLE_NAME
        },
        handleDetail(row) {
            sessionStorage.setItem("formData", JSON.stringify(row))
            window.location.href = './detail.html?nodeKey=' + row.TABLE_NAME;
        }
    }
})